package ds.factcom.view.validate;

import ds.factcom.exception.EmptyStringException;
import ds.factcom.exception.IsNotNumberException;
import ds.factcom.exception.IsNotStringException;
import ds.factcom.exception.NotEquals;

/**
 * 
 * @author Javier De Luca, Maximiliano Herrera, Matias Samblancat
 *
 */
public class Validator {

	public static void isNotEmpty(String string) throws EmptyStringException{
		if ((string == null) || ("".equals(string))){
			throw new EmptyStringException();
		}
	}
	
	public static void correctSelection(String string) throws EmptyStringException, IsNotNumberException{
		isNotEmpty(string);
		isNumber(string);
	}
	
	public static void equals(String oldString, String newString) throws NotEquals{
		if(!(oldString.equals(newString))){
			throw new NotEquals();
		}
	}
	
	public static void isNumber(String string)throws IsNotNumberException {
		try {
			Integer.valueOf(string);
		} catch (NumberFormatException e) {
			throw new IsNotNumberException();
		}
	}

	public static void isString(String string) throws IsNotStringException{
		//TODO(Maxi) hay que implementar el metodo isString(String string)
	}
	
	public static String getNewData(String oldString, String newString){
		String result = oldString;
		if(!(newString.equalsIgnoreCase(oldString))){
			try {
				isNotEmpty(newString);
			} catch (EmptyStringException e) {}
			result = newString;
		}
		return result;
	}
	
	public static Integer getNewData(Integer oldInteger, Integer newInteger){
		//TODO(Maxi) hay que implementar el metodo getNewData(Integer oldInteger, Integer newInteger)
		return 0;
	}
	
	public static Float getNewData(Float oldInteger, Float newInteger){
		
		return 0F;
	}
}
